package com.threeox.commonlibrary.entity.engine.model.listmodel;

import android.widget.RelativeLayout;

import com.threeox.commonlibrary.adapter.base.AutoIntoValAdapter;
import com.threeox.commonlibrary.adapter.base.AutoIntoValExpandAdapter;
import com.threeox.commonlibrary.adapter.navigation.CommonNavigationAdapter;
import com.threeox.commonlibrary.entity.engine.event.BaseEventMessage;
import com.threeox.commonlibrary.entity.engine.model.base.BaseModelMsg;
import com.threeox.commonlibrary.entity.engine.request.base.BaseRequestMsg;
import com.threeox.commonlibrary.entity.engine.request.sqlite.SqliteRequestMsg;
import com.threeox.commonlibrary.request.CommonRequestUtil;
import com.threeox.commonlibrary.ui.view.inter.pullrefresh.IPullToRefLayout;
import com.threeox.commonlibrary.util.CommonConstant;
import com.threeox.commonlibrary.util.CommonConstant.ListViewType;
import com.threeox.utillibrary.util.EmptyUtils;
import com.threeox.utillibrary.util.res.IdHelper;
import com.threeox.utillibrary.util.res.LayoutHelper;
import com.threeox.utillibrary.util.res.StringHelper;

/** 
 *
 * @ClassName: ListModelMsg
 *
 * @Description: Todo(List对象的Model)
 *
 * @author 赵屈犇
 *
 * @date 创建时间:2016/12/21 17:38 
 * 
 * @version 1.0
 */
public class ListModelMsg extends BaseModelMsg {

    private Class adapterClass;// Adapter的Class
    private String adapterName;// Adapter名称

    /*=============布局配置=============*/
    private Integer layoutId;// 布局的Id
    private String layoutName;// 布局的名称
    private String childName;// 可扩展的ListView的list的标签
    private Integer childLayoutId;// 子布局的ID
    private String childLayoutName;// 子布局的名称
    /*=============布局配置=============*/

    /*=============GridView 列数配置=============*/
    private Integer numColumns;// 设置GridView 的列数
    /*=============GridView 列数配置=============*/

    /*=============请求信息配置=============*/
    private Class requestClass;// 请求工具类Class
    private String requestClassName;// 请求的工具类Class名称
    private String pageName;// 翻页的名称
    private Integer pageNum;// 每页显示多少条
    /*=============请求信息配置=============*/

    /*=============View信息配置=============*/
    private boolean isExpan = false;// 是否展开，默认不展开  ExpandableListView
    private boolean isLimit = true;// 默认分页
    private boolean isCalcHig = false;// 默认不自动计算列表高度

    private String viewType;// 列表view的类型  对应ListViewType
    private String headerFooterType;// 显示和隐藏顶部和底部的类型   HeaderFooter
    private Class customViewClass;// 自定义Class
    private String customViewClassName;// 自定义viewclass名称
    /*=============View信息配置=============*/

    /*=============刷新和加载的信息配置=============*/

    private String refreshText;// 刷新的文字
    private String refreshingText;// 刷新中的文字
    private String releaseRefreshText;// 释放刷新的文字
    private String refreshSucceedText;// 刷新成功的文字
    private String refreshFailText;// 刷新失败的文字

    private String loadText;// 加载的文字
    private String loadingText;// 加载中的文字
    private String releaseLoadText;// 释放加载的文字
    private String loadSucceedText;// 加载成功的文字
    private String loadFailText;// 加载失败的文字

    /*=============刷新和加载的信息配置=============*/

    /*=============LetterView配置=============*/
    private String[] charArray;// 导航栏显示的字符数组
    private String charArrayName;// 导航栏显示的字符数组 arrays 的配置文字
    private Integer itemFirstId;// 每列分类出现的首次ViewID
    private String itemFirstIdName;// 每列分类出现的首次View名称
    private boolean isShowNavigationView = false;// 默认不不显示LetterView
    private int alignDisplayPosition = RelativeLayout.ALIGN_RIGHT;// 在RelativeLayout的设置
    private LetterViewDisplayPosition displayPosition = LetterViewDisplayPosition.RIGHT;// 显示LetterView的位置
    /*=============LetterView配置=============*/

    private BaseEventMessage itemClickEvent;// 单列的点击事件信息

    public void initData(StringHelper stringHelper, LayoutHelper layoutHelper, IdHelper idHelper) {
        super.initData(stringHelper, idHelper, layoutHelper);
        this.layoutId = layoutHelper.getLayoutId(layoutName);
        this.childLayoutId = layoutHelper.getLayoutId(childLayoutName);
        if (null != itemClickEvent) {
            itemClickEvent.initData(stringHelper);
        }
        if (null == numColumns) {
            numColumns = 0;
        }
        switch (displayPosition) {
            case TOP:
                alignDisplayPosition = RelativeLayout.ALIGN_PARENT_TOP;
                break;
            case BOTTOM:
                alignDisplayPosition = RelativeLayout.ALIGN_PARENT_BOTTOM;
                break;
            case LEFT:
                alignDisplayPosition = RelativeLayout.ALIGN_PARENT_LEFT;
                break;
            case RIGHT:
                alignDisplayPosition = RelativeLayout.ALIGN_PARENT_RIGHT;
                break;
        }
        if (EmptyUtils.isEmpty(charArray)) {
            charArray = CommonConstant.CHARARRAY;
        }
        if (EmptyUtils.isNotEmpty(charArrayName)) {
            String[] result = stringHelper.getStringArray(charArrayName);
            if (EmptyUtils.isNotEmpty(result)) {
                charArray = result;
            }
        }
        this.itemFirstId = idHelper.getIdByName(itemFirstIdName, IdHelper.ResType.id);
        try {
            if (EmptyUtils.isNotEmpty(adapterName)) {
                this.adapterClass = Class.forName(adapterName);
            } else {
                if (ListViewType.EXPANLISTVIEW.equals(viewType)) {
                    this.adapterClass = AutoIntoValExpandAdapter.class;
                } else {
                    if (isShowNavigationView) {
                        this.adapterClass = CommonNavigationAdapter.class;
                    } else {
                        this.adapterClass = AutoIntoValAdapter.class;
                    }
                }
            }
            if (EmptyUtils.isNotEmpty(requestClassName)) {
                this.requestClass = Class.forName(requestClassName);
            } else {
                this.requestClass = CommonRequestUtil.class;
            }
            initRefreshLoadText(stringHelper);
            if (CommonConstant.HeaderFooter.HideAll.equals(headerFooterType) || CommonConstant.HeaderFooter.HideFooter.equals(headerFooterType)) {
                BaseRequestMsg requestMsg = getBaseRequestMsg();
                if (requestMsg != null && requestMsg instanceof SqliteRequestMsg) {
                    ((SqliteRequestMsg) requestMsg).setLimit(false);
                }
            }
            if (EmptyUtils.isNotEmpty(customViewClassName)) {
                customViewClass = Class.forName(customViewClassName);
            }
        } catch (Exception e) {
        }
    }

    /**
     * 初始化刷新和加载的Text
     *
     * @param stringHelper
     */
    private void initRefreshLoadText(StringHelper stringHelper) {
        this.refreshText = stringHelper.getStringText(refreshText);// 刷新的文字
        this.refreshingText = stringHelper.getStringText(refreshingText);// 刷新中的文字
        this.releaseRefreshText = stringHelper.getStringText(releaseRefreshText);// 释放刷新的文字
        this.refreshSucceedText = stringHelper.getStringText(refreshSucceedText);// 刷新成功的文字
        this.refreshFailText = stringHelper.getStringText(refreshFailText);// 刷新失败的文字

        this.loadText = stringHelper.getStringText(loadText);// 加载的文字
        this.loadingText = stringHelper.getStringText(loadingText);// 加载中的文字
        this.releaseLoadText = stringHelper.getStringText(releaseLoadText);// 释放加载的文字
        this.loadSucceedText = stringHelper.getStringText(loadSucceedText);// 加载成功的文字
        this.loadFailText = stringHelper.getStringText(loadFailText);// 加载失败的文字
    }

    public Class getAdapterClass() {
        return adapterClass;
    }

    public void setAdapterName(String adapterName) {
        this.adapterName = adapterName;
    }

    public Integer getLayoutId() {
        return layoutId;
    }

    public void setLayoutId(Integer layoutId) {
        this.layoutId = layoutId;
    }

    public String getLayoutName() {
        return layoutName;
    }

    public void setLayoutName(String layoutName) {
        this.layoutName = layoutName;
    }

    public String getChildName() {
        return childName;
    }

    public void setChildName(String childName) {
        this.childName = childName;
    }

    public Integer getChildLayoutId() {
        return childLayoutId;
    }

    public void setChildLayoutId(Integer childLayoutId) {
        this.childLayoutId = childLayoutId;
    }

    public String getChildLayoutName() {
        return childLayoutName;
    }

    public void setChildLayoutName(String childLayoutName) {
        this.childLayoutName = childLayoutName;
    }

    public Integer getNumColumns() {
        return numColumns;
    }

    public void setNumColumns(Integer numColumns) {
        this.numColumns = numColumns;
    }


    /**
     *请求信息配置
     */
    public Class getRequestClass() {
        return requestClass;
    }

    public void setRequestClass(Class requestClass) {
        this.requestClass = requestClass;
    }

    public String getRequestClassName() {
        return requestClassName;
    }

    public void setRequestClassName(String requestClassName) {
        this.requestClassName = requestClassName;
    }

    public String getPageName() {
        return pageName;
    }

    public void setPageName(String pageName) {
        this.pageName = pageName;
    }

    public Integer getPageNum() {
        return pageNum;
    }

    public void setPageNum(Integer pageNum) {
        this.pageNum = pageNum;
    }
    /**
     *请求信息配置
     */

    /**
     * View信息配置
     */
    public String getHeaderFooterType() {
        return headerFooterType;
    }

    public String getHeaderFooterType(IPullToRefLayout pullToRefLayout) {
        pullToRefLayout.setHeaderFooterType(headerFooterType);
        return headerFooterType;
    }

    public void setHeaderFooterType(String headerFooterType) {
        this.headerFooterType = headerFooterType;
    }

    public String getViewType() {
        return viewType;
    }

    public void setViewType(String viewType) {
        this.viewType = viewType;
    }

    public String getCustomViewClassName() {
        return customViewClassName;
    }

    public void setCustomViewClassName(String customViewClassName) {
        this.customViewClassName = customViewClassName;
    }

    public Class getCustomViewClass() {
        return customViewClass;
    }

    public void setCustomViewClass(Class customViewClass) {
        this.customViewClass = customViewClass;
    }

    public boolean isExpan() {
        return isExpan;
    }

    public void setIsExpan(boolean expan) {
        isExpan = expan;
    }

    public boolean isLimit() {
        return isLimit;
    }

    public void setIsLimit(boolean limit) {
        isLimit = limit;
    }

    public boolean isCalcHig() {
        return isCalcHig;
    }

    public void setIsCalcHig(boolean calcHig) {
        isCalcHig = calcHig;
    }
    /**
     * View信息配置
     */

    /**
     * NavigationView配置
     */
    public String[] getCharArray() {
        return charArray;
    }

    public void setCharArray(String[] charArray) {
        this.charArray = charArray;
    }

    public String getCharArrayName() {
        return charArrayName;
    }

    public void setCharArrayName(String charArrayName) {
        this.charArrayName = charArrayName;
    }

    public Integer getItemFirstId() {
        return itemFirstId;
    }

    public void setItemFirstId(Integer itemFirstId) {
        this.itemFirstId = itemFirstId;
    }

    public String getItemFirstIdName() {
        return itemFirstIdName;
    }

    public void setItemFirstIdName(String itemFirstIdName) {
        this.itemFirstIdName = itemFirstIdName;
    }

    public boolean isShowNavigationView() {
        return isShowNavigationView;
    }

    public void setIsShowNavigationView(boolean showNavigationView) {
        isShowNavigationView = showNavigationView;
    }

    public LetterViewDisplayPosition getDisplayPosition() {
        return displayPosition;
    }

    public void setDisplayPosition(LetterViewDisplayPosition displayPosition) {
        this.displayPosition = displayPosition;
    }

    public int getAlignDisplayPosition() {
        return alignDisplayPosition;
    }
    /**
     * NavigationView配置
     */

    public BaseEventMessage getItemClickEvent() {
        return itemClickEvent;
    }

    public void setItemClickEvent(BaseEventMessage itemClickEvent) {
        this.itemClickEvent = itemClickEvent;
    }

    /*=============刷新和加载的信息配置=============*/

    public String getRefreshText() {
        return refreshText;
    }

    public void setRefreshText(String refreshText) {
        this.refreshText = refreshText;
    }

    public String getRefreshingText() {
        return refreshingText;
    }

    public void setRefreshingText(String refreshingText) {
        this.refreshingText = refreshingText;
    }

    public String getReleaseRefreshText() {
        return releaseRefreshText;
    }

    public void setReleaseRefreshText(String releaseRefreshText) {
        this.releaseRefreshText = releaseRefreshText;
    }

    public String getRefreshSucceedText() {
        return refreshSucceedText;
    }

    public void setRefreshSucceedText(String refreshSucceedText) {
        this.refreshSucceedText = refreshSucceedText;
    }

    public String getRefreshFailText() {
        return refreshFailText;
    }

    public void setRefreshFailText(String refreshFailText) {
        this.refreshFailText = refreshFailText;
    }

    public String getLoadText() {
        return loadText;
    }

    public void setLoadText(String loadText) {
        this.loadText = loadText;
    }

    public String getLoadingText() {
        return loadingText;
    }

    public void setLoadingText(String loadingText) {
        this.loadingText = loadingText;
    }

    public String getReleaseLoadText() {
        return releaseLoadText;
    }

    public void setReleaseLoadText(String releaseLoadText) {
        this.releaseLoadText = releaseLoadText;
    }

    public String getLoadSucceedText() {
        return loadSucceedText;
    }

    public void setLoadSucceedText(String loadSucceedText) {
        this.loadSucceedText = loadSucceedText;
    }

    public String getLoadFailText() {
        return loadFailText;
    }

    public void setLoadFailText(String loadFailText) {
        this.loadFailText = loadFailText;
    }

    /*=============刷新和加载的信息配置=============*/

}
